package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.SalesDetail;
import com.ruoyi.order.service.ISalesDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售明细管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/system/detail")
public class SalesDetailController extends BaseController
{
    @Autowired
    private ISalesDetailService salesDetailService;

    /**
     * 查询销售明细管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalesDetail salesDetail)
    {
        startPage();
        List<SalesDetail> list = salesDetailService.selectSalesDetailList(salesDetail);
        return getDataTable(list);
    }

    /**
     * 导出销售明细管理列表
     */
   // @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "销售明细管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalesDetail salesDetail)
    {
        List<SalesDetail> list = salesDetailService.selectSalesDetailList(salesDetail);
        ExcelUtil<SalesDetail> util = new ExcelUtil<SalesDetail>(SalesDetail.class);
        util.exportExcel(response, list, "销售明细管理数据");
    }

    /**
     * 获取销售明细管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(salesDetailService.selectSalesDetailByOrderId(orderId));
    }

    /**
     * 新增销售明细管理
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "销售明细管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalesDetail salesDetail)
    {
        return toAjax(salesDetailService.insertSalesDetail(salesDetail));
    }



    /**
     * 修改销售明细管理
     */
   // @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "销售明细管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalesDetail salesDetail)
    {
        return toAjax(salesDetailService.updateSalesDetail(salesDetail));
    }

    /**
     * 删除销售明细管理
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "销售明细管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(salesDetailService.deleteSalesDetailByOrderIds(orderIds));
    }


    //@PreAuthorize("@ss.hasPermi('system:salesDetail:remove')")
    @Log(title = "销售详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteDetail")
    public AjaxResult deleteSalesDetailByOrderIdAndProductId(@RequestParam String orderId, @RequestParam String productId)
    {
        int result = salesDetailService.deleteSalesDetail(orderId, productId);
        return toAjax(result);
    }


}
